
 import { constantRoutes } from '@/router'
import { generatorDynamicRouter } from '@/utils/routerUtil'


const state = {
    routers: constantRoutes,
    addRouters: []
}
const mutations = {
    SET_ROUTERS: (state, routers) => {
        state.addRouters = routers
        state.routers = constantRoutes.concat(routers)
    }
}
const actions = {
    /**
     * 构建获取和构建路由和菜单信息
     * @param commit
     * @param data
     * @returns {Promise<any>}
     * @constructor
     */
    GenerateRoutes({ commit }, data) {
        return new Promise(resolve => {
            generatorDynamicRouter(data).then(routers => {
                commit('SET_ROUTERS', routers)
                resolve(routers)
            })
        })
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}